package com.uls.ldcm.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.uls.ldcm.domain.Contracts;
import com.uls.ldcm.domain.Laborers;
import com.uls.ldcm.service.IContractsService;
import com.uls.ldcm.service.ILaborersService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.uls.common.annotation.Log;
import com.uls.common.core.controller.BaseController;
import com.uls.common.core.domain.AjaxResult;
import com.uls.common.enums.BusinessType;
import com.uls.ldcm.domain.Performance;
import com.uls.ldcm.service.IPerformanceService;
import com.uls.common.utils.poi.ExcelUtil;
import com.uls.common.core.page.TableDataInfo;

/**
 * 工作量考核Controller
 * 
 * @author gw
 * @date 2024-11-11
 */
@RestController
@RequestMapping("/ldcm/performance")
public class PerformanceController extends BaseController
{
    @Autowired
    private IPerformanceService performanceService;

    @Autowired
    private ILaborersService laborersService;

    /**
     * 查询工作量考核列表
     */
    @PreAuthorize("@ss.hasPermi('ldcm:performance:list')")
    @GetMapping("/list")
    public TableDataInfo list(Performance performance)
    {
        startPage();
        List<Performance> list = performanceService.selectPerformanceList(performance);
        for (Performance performance1 : list){
            Laborers laborers = laborersService.selectLaborersById(performance1.getLaborerId());
            performance1.setName(laborers.getName());
        }
        return getDataTable(list);
    }

    /**
     * 导出工作量考核列表
     */
    @PreAuthorize("@ss.hasPermi('ldcm:performance:export')")
    @Log(title = "工作量考核", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Performance performance)
    {
        List<Performance> list = performanceService.selectPerformanceList(performance);
        ExcelUtil<Performance> util = new ExcelUtil<Performance>(Performance.class);
        util.exportExcel(response, list, "工作量考核数据");
    }

    /**
     * 获取工作量考核详细信息
     */
    @PreAuthorize("@ss.hasPermi('ldcm:performance:query')")
    @GetMapping(value = "/{performanceId}")
    public AjaxResult getInfo(@PathVariable("performanceId") Long performanceId)
    {
        return success(performanceService.selectPerformanceByPerformanceId(performanceId));
    }

    /**
     * 新增工作量考核
     */
    @PreAuthorize("@ss.hasPermi('ldcm:performance:add')")
    @Log(title = "工作量考核", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Performance performance)
    {
        return toAjax(performanceService.insertPerformance(performance));
    }

    /**
     * 修改工作量考核
     */
    @PreAuthorize("@ss.hasPermi('ldcm:performance:edit')")
    @Log(title = "工作量考核", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Performance performance)
    {
        return toAjax(performanceService.updatePerformance(performance));
    }

    /**
     * 删除工作量考核
     */
    @PreAuthorize("@ss.hasPermi('ldcm:performance:remove')")
    @Log(title = "工作量考核", businessType = BusinessType.DELETE)
	@DeleteMapping("/{performanceIds}")
    public AjaxResult remove(@PathVariable Long[] performanceIds)
    {
        return toAjax(performanceService.deletePerformanceByPerformanceIds(performanceIds));
    }
}
